//
//  CircleView.m
//  YKL
//
//  Created by Apple on 15/12/7.
//  Copyright © 2015年 Apple. All rights reserved.
//

#import "XLCircleProgress.h"
#import "XLCircle.h"


@interface XLCircleProgress ()
//百分比
@property (nonatomic, weak) UIButton *startOrPauseBtn;
@end
@implementation XLCircleProgress
{
    XLCircle* _circle;
    UILabel *_percentLabel;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}


-(void)initUI
{
    float lineWidth = 2;
//    _percentLabel = [[UILabel alloc] initWithFrame:self.bounds];
//    _percentLabel.textColor = [UIColor whiteColor];
//    _percentLabel.textAlignment = NSTextAlignmentCenter;
//    _percentLabel.font = [UIFont boldSystemFontOfSize:50];
//    _percentLabel.text = @"0%";
//    [self addSubview:_percentLabel];
    
    _circle = [[XLCircle alloc] initWithFrame:self.bounds lineWidth:lineWidth];
    [self addSubview:_circle];
    
    UIButton *btn = [[UIButton alloc] initWithFrame:self.bounds];
    [btn setTitle:@"" forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"task_pause_state.png"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"task_loading_state.png"] forState:UIControlStateSelected];
    [btn addTarget:self action:@selector(startOrPauseAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    self.startOrPauseBtn = btn;
}

- (void)startOrPauseAction:(UIButton *)btn {
    if (self.clickActionBlock) {
        self.clickActionBlock(!btn.selected);
    }
}
#pragma mark -
#pragma mark Setter方法
-(void)setProgress:(float)progress
{
    _progress = progress;
    _circle.progress = progress;
//    [self setLoadingState];
//    _percentLabel.text = [NSString stringWithFormat:@"%.0f%%",progress*100];
}
- (void)setLoadingState {
    self.startOrPauseBtn.selected = YES;
}

- (void)setPauseState {
    self.startOrPauseBtn.selected = NO;
}
@end
